package com.zhentao.tot.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.zhentao.tot.domain.ApArticleContent;
import com.zhentao.tot.service.IApArticleContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zhentao.tot.mapper.ApArticleMapper;
import com.zhentao.tot.domain.ApArticle;
import com.zhentao.tot.service.IApArticleService;

/**
 * App文章Service业务层处理
 *
 * @author ruoyi
 * @date 2025-04-23
 */
@Service
public class ApArticleServiceImpl implements IApArticleService
{
    @Autowired
    private ApArticleMapper apArticleMapper;
    @Autowired
    private IApArticleContentService iApArticleContentService;

    /**
     * 查询App文章
     *
     * @param id App文章主键
     * @return App文章
     */
    @Override
    public ApArticle selectApArticleById(Integer id) {
      ApArticle apArticle=  apArticleMapper.selectApArticleById(id);
        System.err.println(apArticle);
        ApArticleContent apArticleContent = iApArticleContentService.selectApArticleContentArticleId(apArticle.getId());
        apArticle.setContent(apArticleContent.getContent());
        System.err.println(apArticleContent+"查询");
        return apArticle;
    }

    /**
     * 查询App文章列表
     *
     * @param apArticle App文章
     * @return App文章
     */
    @Override
    public List<ApArticle> selectApArticleList(ApArticle apArticle){
        List<ApArticle> apArticles = apArticleMapper.selectApArticleList(apArticle);
//        System.err.println(apArticles);
//        List<ApArticleContent> apArticleContent=iApArticleContentService.selectApArticleContentLists();
//        apArticle.setApArticleContent(apArticleContent);
        return apArticles;
    }

    /**
     * 新增App文章
     *
     * @param apArticle App文章
     * @return 结果
     */
    @Override
    public int insertApArticle(ApArticle apArticle) {
       int i= apArticleMapper.insertApArticle(apArticle);
       ApArticleContent apArticleContent=new ApArticleContent();
       apArticleContent.setContent(apArticle.getContent());
       apArticleContent.setArticleId(apArticle.getId());
        int i1 = iApArticleContentService.insertApArticleContent(apArticleContent);
        return i;
    }

    /**
     * 修改App文章
     *
     * @param apArticle App文章
     * @return 结果
     */
    @Override
    public int updateApArticle(ApArticle apArticle) {
       int i= apArticleMapper.updateApArticle(apArticle);
       ApArticleContent apArticleContent=new ApArticleContent();
       apArticleContent.setContent(apArticle.getContent());
       apArticleContent.setArticleId(apArticle.getId());
        System.err.println(apArticleContent+"修改");
        int i1 = iApArticleContentService.updateApArticleContentArticleId(apArticleContent);
        return i;
    }

    /**
     * 批量删除App文章
     *
     * @param ids 需要删除的App文章主键
     * @return 结果
     */
    @Override
    public int deleteApArticleByIds(Integer[] ids) {
     int i=   apArticleMapper.deleteApArticleByIds(ids);
        int i1 = iApArticleContentService.deleteApArticleContentByArticleIds(ids);
        return i;
    }

    /**
     * 删除App文章信息
     *
     * @param id App文章主键
     * @return 结果
     */
    @Override
    public int deleteApArticleById(Integer id) {
     int i=  apArticleMapper.deleteApArticleById(id);
        int i1 = iApArticleContentService.deleteApArticleContentByArticleId(id);
        return i;
    }
}
